package com.angus.modules.content.controller.common;

import com.angus.common.core.web.controller.BaseController;
import com.angus.common.core.web.domain.AjaxResult;
import com.angus.common.security.utils.SecurityUtils;
import com.angus.modules.content.service.SearchContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

@RestController
@Validated // 关键注解：启用方法参数校验
@RequestMapping("/search")
public class SearchContentController extends BaseController {

    @Autowired
    private SearchContentService searchContentService;

    @GetMapping("/word")
    public AjaxResult searchContent(@RequestParam (required = false) @NotBlank(message = "搜索词不能为空") String searchWord){
        startPage();
        Long userId = SecurityUtils.getUserId();
        return AjaxResult.success(searchContentService.getSearchContentList(searchWord, userId));
    }
}
